package com.hazy.animalface;

import android.app.Application;
import android.os.Environment;

import com.avos.avoscloud.AVAnalytics;
import com.avos.avoscloud.AVOSCloud;
import com.avos.avoscloud.AVObject;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.hazy.animalface.constants.Parameters;
import com.hazy.animalface.module.Sticker;
import com.hazy.animalface.module.StickerBag;
import com.umeng.socialize.Config;
import com.umeng.socialize.PlatformConfig;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.common.QueuedWork;

import java.io.File;

public class App extends Application {

    @Override
    public void onCreate() {

        super.onCreate();
        //开启debug模式，方便定位错误，具体错误检查方式可以查看http://dev.umeng.com/social/android/quick-integration的报错必看，正式发布，请关闭该模式
        Config.DEBUG = true;
        QueuedWork.isUseThreadPool = false;
        createHazy();
        UMShareAPI.get(this);
        Fresco.initialize(this);
        initLeanCould();
        registerSubClass();
    }

    public static File createHazy() {
        String path = Environment.getExternalStorageDirectory() + "/Animal";
        File mHazyFile = new File(path);
        if (!mHazyFile.exists()) mHazyFile.mkdir();
        return mHazyFile;
    }

    public static String createHazy(String dirName) {
        String path = Environment.getExternalStorageDirectory() + "/Animal/" + dirName;
        File mHazyFile = new File(path);
        if (!mHazyFile.exists()) mHazyFile.mkdir();
        return path;
    }

    //各个平台的配置，建议放在全局Application或者程序入口
    {
        PlatformConfig.setWeixin("wxdc1e388c3822c80b", "3baf1193c85774b3fd9d18447d76cab0");
        PlatformConfig.setSinaWeibo("3921700954", "04b48b094faeb16683c32669824ebdad", "http://sns.whalecloud.com");
        PlatformConfig.setQQZone("100424468", "c7394704798a158208a74ab60104f0ba");
        PlatformConfig.setAlipay("2015111700822536");
    }

    private void initLeanCould() {
        AVOSCloud.initialize(this, Parameters.LEANCLOUD_APPID, Parameters.LEANCLOUD_APPKEY);
        AVOSCloud.setDebugLogEnabled(true);
        AVAnalytics.enableCrashReport(this, true);
    }

    private void registerSubClass() {
        AVObject.registerSubclass(Sticker.class);
        AVObject.registerSubclass(StickerBag.class);
    }
}
